package com.example.demo.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class TextResourceConfig implements InitializingBean {
    Logger logger = LoggerFactory.getLogger(TextResourceConfig.class);

    private final VectorStore vectorStore;

    @Value("classpath:test.txt")
    private Resource resource;

    @Override
    public void afterPropertiesSet() throws Exception {
        JsonReader jsonReader = new JsonReader(new FileSystemResource("src/main/resources/test.json"),
                "question", "answer");
        List<Document> documents = jsonReader.get();
        logger.info("jsonReader: {}", documents);
        vectorStore.add(documents);
    }

}
